//
//  DLScreeningView.m
//  delongzhitou
//
//  Created by Mr.Wang on 2018/12/18.
//  Copyright © 2018 delongzhitou. All rights reserved.
//

#import "DLScreeningView.h"

@interface DLScreeningView ()



@end


@implementation DLScreeningView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self layoutSubControls];
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}
- (void) layoutSubControls {
    //107 42
    
    CGFloat buttonWidth = kAutoWidth(107);
    CGFloat buttonHeight = kAutoWidth(42);
    
    CGFloat margin = (kScreenWidth - buttonWidth * 3) / 4;
    NSArray *searchArr = @[@"全部", @"日收益", @"累计收益", @"近一周收益", @"近一月收益"];
    
    for (NSInteger i = 0; i < searchArr.count; i++) {
        UIButton *button = [UIButton buttonWithType:0];
        button.frame = CGRectMake(margin + (buttonWidth + margin) *(i % 3), margin + (buttonHeight + margin) *(i / 3), buttonWidth, buttonHeight);
        button.titleLabel.font = kSystemFont(14);
        [button setTitleColor:kColorRGB(102, 102, 102) forState:UIControlStateNormal];
        [button setTitleColor:kDLBtnNormalBgColor forState:UIControlStateSelected];
        [button setTitle:searchArr[i] forState:UIControlStateNormal];
        button.adjustsImageWhenHighlighted = NO;
        button.tag = 200 + i;
        button.layer.cornerRadius = 2;
        button.layer.borderWidth = 0.5;
        
        if (i == 0) {
            button.selected = YES;
            button.backgroundColor = kColorRGB(216, 237, 254);
            button.layer.borderColor = kColorRGB(169, 212, 252).CGColor;
        } else {
            button.backgroundColor = [UIColor whiteColor];
            button.layer.borderColor = kColorRGB(200, 200, 200).CGColor;
        }
        
        [self addSubview:button];
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    UIButton *cancelButton = [UIButton buttonWithType:0];
    cancelButton.frame = CGRectMake(0, self.height - kAutoWidth(49), kScreenWidth / 2, kAutoWidth(49));
    cancelButton.backgroundColor = [UIColor whiteColor];
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    cancelButton.titleLabel.font = kSystemFont(17);
    [cancelButton setTitleColor:kDLNormalBlackColor forState:UIControlStateNormal];
    cancelButton.layer.borderWidth = 1;
    cancelButton.layer.borderColor = kColorRGB(200, 200, 200).CGColor;
    [self addSubview:cancelButton];
    cancelButton.tag = 100;
    [cancelButton addTarget:self action:@selector(cancelButtonClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *selectButton = [UIButton buttonWithType:0];
    selectButton.frame = CGRectMake(cancelButton.right, cancelButton.top, cancelButton.width, cancelButton.height);
    selectButton.backgroundColor = kDLBtnNormalBgColor;
    [selectButton setTitle:@"确认" forState:UIControlStateNormal];
    selectButton.titleLabel.font = kSystemFont(17);
    [selectButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self addSubview:selectButton];
    selectButton.tag = 101;
    [selectButton addTarget:self action:@selector(selectButtonClick) forControlEvents:UIControlEventTouchUpInside];
    
}
- (void) dismissSelf {
    [UIView animateWithDuration:0.2 animations:^{
        self.alpha = 0;
    }];
}
- (void) selectButtonClick {
    [self dismissSelf];
}
- (void) cancelButtonClick {
    [self dismissSelf];
}
- (void) buttonClick:(UIButton *)button {
    for (UIButton *selectButton in self.subviews) {
        if (selectButton.tag > 199) {
            selectButton.selected = NO;
            selectButton.backgroundColor = [UIColor whiteColor];
            selectButton.layer.borderColor = kColorRGB(200, 200, 200).CGColor;
        }
    }
    button.selected = YES;
    button.backgroundColor = kColorRGB(216, 237, 254);
    button.layer.borderColor = kColorRGB(169, 212, 252).CGColor;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
